package com.kong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.kong.constant.MessageConstant;
import com.kong.entity.PageResult;
import com.kong.entity.QueryPageBean;
import com.kong.entity.Result;
import com.kong.entity.RoleParams;
import com.kong.pojo.Role;
import com.kong.service.RoleService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author yang2013
 * @data 2020/10/21 13:10
 */
@RestController
@RequestMapping("/role")
public class RoleController {
    @Reference
    private RoleService roleService;

    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<Role> roles=roleService.findAll();
            return new Result(true, MessageConstant.QUERY_ROLE_SUCCESS,roles);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_ROLE_FAIL);
        }
    }

    @PostMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
        try {
            PageResult pageResult=roleService.findByPage(queryPageBean);
            return new Result(true,MessageConstant.QUERY_ROLE_SUCCESS,pageResult);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_ROLE_FAIL);
        }
    }


    @PostMapping("/add")
    public Result add(@RequestBody RoleParams params){
        try {
            System.out.println(params.toString());
            return null;
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_ADD_FAIL);
        }
    }


}
